class Solution {
public:
    vector<int> getMaxMatrix(vector<vector<int>>& matrix) {
        int n = matrix.size(), m = matrix[0].size();
        int sum = INT_MIN;
        int a, b, c, d;
        for (int i = 0; i < n; i++)
        {
            vector<int> dp(m, 0);
            for (int j = i; j < n; j++)
            {
                for (int l = 0, r = 0, pre = INT_MIN; r < m; r++)
                {
                    dp[r] += matrix[j][r];
                    if (pre >= 0)
                        pre += dp[r];
                    else
                    {
                        pre = dp[r];
                        l = r;
                    }

                    if (pre > sum)
                    {
                        a = i;
                        b = l;
                        c = j;
                        d = r;
                        sum = pre;
                    }
                }
            }
        }
        return { a, b, c, d };
    }

};